import { PartnersBiddingList } from '@/lib/bidding/vendor/partners-bidding-list'
import * as React from "react"
import { getServerSession } from 'next-auth'
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { getBiddingListForPartners } from '@/lib/bidding/detail/service'
import { Shell } from '@/components/shell'
import { DataTableSkeleton } from '@/components/data-table/data-table-skeleton'

export default async function PartnersBidPage() {
  // 세션에서 companyId 가져오기
  const session = await getServerSession(authOptions)
  const companyId = session?.user?.companyId

  if (!companyId) {
    return (
      <div className="container mx-auto py-6">
        <div className="text-center">
          <h1 className="text-2xl font-bold text-destructive">회사 정보가 없습니다. 다시 로그인 해주세요.</h1>
        </div>
      </div>
    )
  }

  // 서버 사이드에서 입찰 목록 데이터 가져오기
  const promises = Promise.all([
    getBiddingListForPartners(companyId),
  ])

  return (
    <Shell className="gap-2">
    <div className="container mx-auto py-6 space-y-6">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-3xl font-bold">입찰 참여</h1>
          <p className="text-muted-foreground mt-2">
            참여 가능한 입찰 목록을 확인하고 응찰하실 수 있습니다.
          </p>
        </div>
      </div>

      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={6}
            searchableColumnCount={1}
            filterableColumnCount={2}
            cellWidths={["10rem", "40rem", "12rem", "12rem", "8rem", "8rem"]}
            shrinkZero
          />
        }
      >        
      <PartnersBiddingList companyId={companyId} promises={promises} />
      </React.Suspense>
      </div>
    </Shell>
  )
}

